home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / AEGestalt 1.0 / UAEDocument.cp < prev    next >
Encoding:
Text File  |  1992-07-15  |  8.8 KB  |  353 lines  |  [TEXT/MPS ]

  1. //     UAEDocument.cp 
  2. //     Copyright © 1991-92 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains the basic TAEDocument member functions
  5. //
  6. //    <1>        khs        1.0        First final version
  7.  
  8.  
  9. // INCLUDES
  10. #ifndef __AEDOCUMENT__
  11. #include "UAEDocument.h"                                        
  12. #endif
  13.  
  14.  
  15. //    CLASS METHODS 
  16. //    Empty constructor - for avoiding ptabs in global data space
  17. #pragma segment ARes
  18. TAEDocument::TAEDocument()
  19. {
  20. }
  21.  
  22. //    Create TAEDocument
  23. #pragma segment AInit
  24. pascal void TAEDocument::IAEDocument()
  25. {
  26.     inherited::IDocument();
  27.     
  28.     // initialize handle to AE
  29.     fAEGestaltAddress.descriptorType = typeNull;
  30.     fAEGestaltAddress.dataHandle = NULL;
  31.     fConfigurationInfo = NULL;
  32.     fOKNode = FALSE;
  33. }
  34.  
  35.  
  36. //    Create any needed TDocument Views
  37. #pragma segment AOpen
  38. pascal void TAEDocument::DoMakeViews(Boolean    /*forPrinting*/)
  39. {
  40.     TWindow * aWindow = NULL;
  41.     FailInfo fi;
  42.  
  43.     if (fi.Try())
  44.     {
  45.         // create Main Information Window    
  46.         aWindow = (TWindow *)gViewServer->NewTemplateWindow(kMainWindow, this);
  47.  
  48.         // find text views
  49.         fInfoField = (TStaticText *)aWindow->FindSubView('info');
  50.         fLabelView = (TLabelView *)aWindow->FindSubView('VIW1);
  51.         fInfoView    = (TInformationView *)aWindow->FindSubView('VIW2');
  52.  
  53.         // find buttons
  54.         fFindButton = (TButton *)aWindow->FindSubView('find');
  55.         fReportButton = (TButton *)aWindow->FindSubView('repo');
  56.  
  57.  
  58. //    Add Adorners to various views - yes this would be far better to do
  59. //    from the resource file itself, but as long as there's no ViewEdit 3.0
  60. //    which handles the new format, I'm hesitant to hack in by hand these
  61. //    values, because it's a tidy exersize.
  62.  
  63.         // add window adorners, fill gray background
  64.         aWindow->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  65.                                             kAdornBefore, kRedraw);
  66.                                             
  67.         // add view adorners, frame second view
  68.         fInfoView->AddAdorner(NewStdAdorner('fram', "", 'fram', kFreeOnDeletion),
  69.                                             kDrawView, kRedraw);
  70.         fInfoView->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  71.                                             kDrawView, kRedraw);
  72.         
  73.         // add static text adorner, erase background
  74.         fInfoField->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  75.                                                 kDrawView, kRedraw);
  76.         fi.Success();
  77.     }
  78.     else
  79.         fi.ReSignal();
  80. }
  81.  
  82.  
  83. //    Handle Events passed to TDocument, like the find button event
  84. #pragma segment AMain
  85. pascal void TAEDocument::DoEvent(EventNumber eventNumber,
  86.                                  TEventHandler* source,
  87.                                  TEvent* event)
  88. {
  89.     if (eventNumber == mButtonHit)
  90.     {
  91.         // were any of the buttons pressed?
  92.         if (source->fIdentifier == 'find')
  93.         {
  94.             // find button?    
  95.             // post a menu command which translates to the Find… menu entry    
  96.             this->HandleMenuCommand(cFindAEGestalt);
  97.         }
  98.  
  99.         else if (source->fIdentifier == 'repo')
  100.         {
  101.             // report button & we have valid node?
  102.             if (fOKNode)
  103.             // post a menu command which translates to the Report… menu entry    
  104.                 this->HandleMenuCommand(cCreateReport);
  105.         }
  106.     }
  107.     else
  108.         inherited::DoEvent(eventNumber, source, event);
  109. }
  110.  
  111.  
  112. //    Free any resources attached to the TDocument, take also care of AE resources
  113. #pragma segment AClose
  114. pascal void TAEDocument::Free()
  115. {
  116.     AEAddressDesc aDesc = fAEGestaltAddress;
  117.     // dispose the descriptor!
  118.     AEDisposeDesc(aDesc);
  119.  
  120.     inherited::Free();
  121. }
  122.  
  123.  
  124. //    Setup menus when TDocument is created
  125. #pragma segment ARes
  126. pascal void TAEDocument::DoSetupMenus()
  127. {
  128.     inherited::DoSetupMenus();
  129.  
  130.     // we assume that we are starting from a Find command
  131.     Enable(cFindAEGestalt, TRUE);
  132.  
  133.     // we can't report anything until we have information
  134.     Enable(cCreateReport, fAEGestaltAddress.dataHandle != NULL);
  135.     fReportButton->DimState(!(fAEGestaltAddress.dataHandle != NULL), TRUE);
  136. }
  137.  
  138.  
  139. //    Handle menu commands assigned to the TDocument controlled menus
  140. #pragma segment ASelCommand
  141. pascal void TAEDocument::DoMenuCommand(CommandNumber theNumber)
  142. {
  143.     TCommand * cmdToPost = NULL;
  144.     TAEClientCommand * AEcmd = NULL;
  145.     TLookupCommand * aLookup = NULL;
  146.  
  147.  
  148.     switch (theNumber)
  149.     {
  150.         case cFindAEGestalt:
  151.             aLookup = new TLookupCommand;
  152.             aLookup->ILookupCommand(cFindAEGestalt, this);
  153.             cmdToPost = aLookup;
  154.             fInfoField->SetText("Look for node to examine...", TRUE);
  155.             break;
  156.  
  157.         case cCreateReport:
  158.             AEcmd = new TAEClientCommand;
  159.             AEcmd->IAEClientCommand(cCreateReport, this, kAEGetConfig);
  160.             cmdToPost = AEcmd;
  161.             fInfoField->SetText("Report node information...", TRUE);
  162.             break;
  163.  
  164.         default:
  165.             inherited::DoMenuCommand(theNumber);
  166.     }
  167.     if (cmdToPost != NULL)
  168.         this->PostAnEvent(cmdToPost);
  169. }
  170.  
  171.  
  172. //    Return the AppleEvents address stored in TAEDocument
  173. #pragma segment ARes
  174. pascal void TAEDocument::GetAEGestaltAddress(AEAddressDesc& theAddress)
  175. {
  176.     theAddress = fAEGestaltAddress;
  177. }
  178.  
  179.  
  180. //    Read the Configuration information
  181. #pragma segment Main
  182. pascal void TAEDocument::ReadConfiguration(Configuration* theConfig)
  183. {
  184.     BlockMove(&theConfig, &fConfigurationInfo, sizeof(theConfig));
  185. }
  186.  
  187.  
  188. //    Process the information we got from the AE for the View class for
  189. //    later display
  190. #pragma segment Main
  191. pascal void TAEDocument::ProcessAEInformation()
  192. {
  193.     switch (fConfigurationInfo->machineType)
  194.     {                                            // Label1 - Machine Type
  195.         case 1:
  196.             fInfoView->fLabel1 = "Classic";
  197.             break;
  198.         case 2:
  199.             fInfoView->fLabel1 = "MacXL";
  200.             break;
  201.         case 3:
  202.             fInfoView->fLabel1 = "Mac512KE";
  203.             break;
  204.         case 4:
  205.             fInfoView->fLabel1 = "Mac Plus";
  206.             break;
  207.         case 5:
  208.             fInfoView->fLabel1 = "MacSE";
  209.             break;
  210.         case 6:
  211.             fInfoView->fLabel1 = "MacII";
  212.             break;
  213.         case 7:
  214.             fInfoView->fLabel1 = "MacIIx";
  215.             break;
  216.         case 8:
  217.             fInfoView->fLabel1 = "MacIIcx";
  218.             break;
  219.         case 9:
  220.             fInfoView->fLabel1 = "MacSe030";
  221.             break;
  222.         case 10:
  223.             fInfoView->fLabel1 = "Portable";
  224.             break;
  225.         case 11:
  226.             fInfoView->fLabel1 = "MacIIci";
  227.             break;
  228.         case 13:
  229.             fInfoView->fLabel1 = "MacIIfx";
  230.             break;
  231.         case 17:
  232.             fInfoView->fLabel1 = "Mac Classic";
  233.             break;
  234.         case 18:
  235.             fInfoView->fLabel1 = "MacIIsi";
  236.             break;
  237.         case 19:
  238.             fInfoView->fLabel1 = "MacLC";
  239.             break;
  240.         case 20:
  241.             fInfoView->fLabel1 = "Quadra 900";
  242.             break;
  243.         case 21:
  244.             fInfoView->fLabel1 = "PowerBook 140";
  245.             break;
  246.         case 22:
  247.             fInfoView->fLabel1 = "Quadra 700";
  248.             break;
  249.         case 23:
  250.             fInfoView->fLabel1 = "Classic II";
  251.             break;
  252.         case 24:
  253.             fInfoView->fLabel1 = "PowerBook 100";
  254.             break;
  255.         case 25:
  256.             fInfoView->fLabel1 = "PowerBook 140";
  257.             break;
  258.         default:
  259.             fInfoView->fLabel1 = "Unknown type";
  260.             break;
  261.     }
  262.  
  263.     if (fConfigurationInfo->systemVersion == 0x700)// Label2 - System Version
  264.         fInfoView->fLabel2 = "System 7.0";
  265.     else if (fConfigurationInfo->systemVersion == 0x701)
  266.         fInfoView->fLabel2 = "System 7.0.1";
  267.     else if (fConfigurationInfo->systemVersion == 0x602)
  268.         fInfoView->fLabel2 = "System 6.0.2";
  269.     else if (fConfigurationInfo->systemVersion == 0x603)
  270.         fInfoView->fLabel2 = "System 6.0.3";
  271.     else if (fConfigurationInfo->systemVersion == 0x604)
  272.         fInfoView->fLabel2 = "System 6.0.4";
  273.     else if (fConfigurationInfo->systemVersion == 0x605)
  274.         fInfoView->fLabel2 = "System 6.0.5";
  275.     else if (fConfigurationInfo->systemVersion == 0x607)
  276.         fInfoView->fLabel2 = "System 6.0.7";
  277.     else if (fConfigurationInfo->systemVersion < 0x600)
  278.         fInfoView->fLabel2 = "Pre 6.0.x System";
  279.     else if (fConfigurationInfo->systemVersion > 0x701)
  280.         fInfoView->fLabel2 = "Post 7.0.1 System";
  281.  
  282.     switch (fConfigurationInfo->processor)
  283.     {                                            // Label3 - Processor Type
  284.         case 1:
  285.             fInfoView->fLabel3 = "68000";
  286.             break;
  287.         case 2:
  288.             fInfoView->fLabel3 = "68010";
  289.             break;
  290.         case 3:
  291.             fInfoView->fLabel3 = "68020";
  292.             break;
  293.         case 4:
  294.             fInfoView->fLabel3 = "68030";
  295.             break;
  296.         case 5:
  297.             fInfoView->fLabel3 = "68040";
  298.             break;
  299.         default:
  300.             fInfoView->fLabel3 = "Unknown CPU";
  301.             break;
  302.     }
  303.  
  304.     if (fConfigurationInfo->hasFPU)                // Label4 - Has FPU?
  305.         fInfoView->fLabel4 = "TRUE";
  306.     else
  307.         fInfoView->fLabel4 = "FALSE";
  308.  
  309.     if (fConfigurationInfo->hasColorQD)            // Label5 - Has Color QD?
  310.         fInfoView->fLabel5 = "TRUE";
  311.     else
  312.         fInfoView->fLabel5 = "FALSE";
  313.  
  314.     if (fConfigurationInfo->has32BitQD)            // Label6 - Has 32-bit QD?
  315.         fInfoView->fLabel6 = "TRUE";
  316.     else
  317.         fInfoView->fLabel6 = "FALSE";
  318.  
  319.     if (fConfigurationInfo->hasSCSI)            // Label7 - Has SCSI?
  320.         fInfoView->fLabel7 = "TRUE";
  321.     else
  322.         fInfoView->fLabel7 = "FALSE";
  323.  
  324.     if (fConfigurationInfo->hasAppleEventMgr)    // Label8 - Has AppleEvent Mgr?
  325.         fInfoView->fLabel8 = "TRUE";
  326.     else
  327.         fInfoView->fLabel8 = "FALSE";
  328.  
  329.     if (fConfigurationInfo->hasEditionMgr)        // Label9 - Has Edition Mgr?
  330.         fInfoView->fLabel9 = "TRUE";
  331.     else
  332.         fInfoView->fLabel9 = "FALSE";
  333.  
  334.     if (fConfigurationInfo->hasAUX)                // Label10 - Is A/UX System?
  335.         fInfoView->fLabel10 = "TRUE";
  336.     else
  337.         fInfoView->fLabel10 = "FALSE";
  338.  
  339.     if (fConfigurationInfo->hasTrueType)        // Label11 - Has TrueType?
  340.         fInfoView->fLabel11 = "TRUE";
  341.     else
  342.         fInfoView->fLabel11 = "FALSE";
  343.  
  344.     CStr255 tempString;                            // Label12 - AppleTalk version
  345.     NumToString(long(fConfigurationInfo-> atDrvrVersNum), tempString);
  346.     fInfoView->fLabel12 = tempString;
  347.  
  348.     fInfoView->fHasGestaltInfo = TRUE;            // report for view to draw
  349.     fInfoView->ForceRedraw();                    // redraw the view
  350. }
  351.  
  352.  
  353.